<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>通知公告</title>
    <script src="../../res/layui/layui.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" type="text/css">
    <script src="../../res/js/Tools.js" charset="utf-8"></script>
    <script src="../../res/js/jquery-3.1.1.min.js" charset="utf-8"></script>
</head>
<body>
<input type="hidden" id="title">
<input type="hidden" id="date1">
<input type="hidden" id="date2">
<input type="hidden" id="issuer">
<table class="layui-hide" id="test" lay-filter="test"></table>
<script type="text/html" id="toolbarDemo">
    <div id="kool">
        <div class="layui-inline">
            <input type="text" placeholder="标题" class="layui-input" id="attachName">
        </div>
        <div class="layui-inline">
            <input class="layui-input" name="newsTimeS" id="newsTimeS"
                   placeholder="开始时间" autocomplete="off">
        </div>
        <div class="layui-inline">
            <input class="layui-input" name="newsTimeE" id="newsTimeE"
                   placeholder="结束时间" autocomplete="off">
        </div>
        <div class="layui-inline" id="fbUser">
            <input type="text" placeholder="发布人" class="layui-input" id="attachPublisher">
        </div>
        <input type="button" value="查询" class="layui-btn" lay-event="select">
        <input type="button" value="刷新" class="layui-btn layui-btn-normal" lay-event="reload">
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit" >查看</a>
</script>
<script type="text/html" id="switchTpl2">
    {{# if(d.auditState==10){ }}
    发布
    {{# } else if(d.auditState==20){}}
    等待审核
    {{# } else if(d.auditState==25){}}
    未通过
    {{# } else if(d.auditState==30){}}
    通过
    {{# } }}
</script>
<script type="text/html" id="switchTpl3">
    {{# if(d.attachType==10){ }}
    通知公告
    {{# } else if(d.attachType==20){}}
    公务信息
    {{# } else if(d.attachType==40){}}
    学习资料
    {{# } else if(d.attachType==30){}}
    文件政策
    {{# } }}
</script>
<script type="text/html" id="switchTpl">
    <input type="checkbox" name="sex" value="{{d.attachId}}" disabled="" lay-skin="switch" lay-text="是|否" lay-filter="sexDemo" {{ d.isAudit == 2 ? 'checked' : '' }}>
</script>
<script type="text/html" id="switchTpl1">
    <input type="checkbox" name="sex" value="{{d.isva}}" disabled="" lay-skin="switch" lay-text="是|否" lay-filter="sexDemo" {{ d.isva == 1 ? 'checked' : '' }}>
</script>
<script>
    $(function(){
        titleupdate();//标题更改
        newTime();//加入时间框
    })
    function titleupdate(){
        var attachType=getQueryString("attachType");
        if(attachType==10){
            document.title = '通知公告';
        }else if(attachType==20){
            document.title = '公务信息';
        }else if(attachType==30){
            document.title = '文件政策';
        }else if(attachType==40){
            document.title='学习资料';
        }
    }
    //给隐藏条件框赋值
    function hidevalue(){
        $("#title").val($("#attachName").val());
        $("#date1").val($("#newsTimeS").val());
        $("#date2").val($("#newsTimeE").val());
        $("#issuer").val($("#attachPublisher").val());
    }
    //条件查询框赋值
    function formvalue(){
        $("#attachName").val($("#title").val());
        $("#newsTimeS").val($("#date1").val());
        $("#newsTimeE").val($("#date2").val());
        $("#attachPublisher").val($("#issuer").val());
    }
    //选择时间框的方法
    function newTime(){
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            //常规用法
            laydate.render({
                elem: '#newsTimeS'
                ,type: 'date'
            });
            //常规用法
            laydate.render({
                elem: '#newsTimeE'
                ,type: 'date'    //可以选择时间
            });
        });
    }
</script>
<script>
    //全局同步
    $.ajaxSetup({
        async:false
    });
    var table2 = "";
    var attachType = getQueryString("attachType");
    var url="../../AtsAttachmentAction/select";
    if(attachType!=null){
        url+="?auditState=10&attachType="+attachType
        var urls="../../AtsAttachmentAction/selectEmp";
        var look="";
        $.post(urls,null,function(obj){
            $.each(obj,function(index,item){
                if(item.attachId!=null){
                    look+=item.attachId;
                }
            })
        },'json')
        url+="&isva=1&attachIdLike="+look;
    }
    layui.use('table', function(){
        var table = layui.table
            ,form = layui.form;
        table2=table.render({
            elem: '#test'
            ,url:url
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '通知公告表'
            ,cols: [[
                {field:'', title:'', width:50}
                ,{type: 'numbers',title:'序号',width:40}
                ,{field:'attachName', title:'标题', width:100}
                ,{field:'attachContent', title:'内容', width:100}
                ,{field:'attachPublisher', title:'发布人', width:100}
                ,{field:'attachTime', title:'发布时间', width:120,templet: "<div>{{layui.util.toDateString(d.attachTime, 'yyyy-MM-dd')}}</div>"}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width:80}
            ]]
            ,page: true
        });
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'delAll':
                    var data = checkStatus.data;
                    //layer.alert(JSON.stringify(data));
                    $.each(data,function(index,item){
                        if(item.roleValidity==1){
                            var url="../Role/updateRolevalidity.action";
                            var data={roleId:item.roleId,roleValidity:0};
                            $.post(url,data);
                            layer.msg("修改成功");
                            table2.reload();
                        }
                    })
                    break;
                case 'add'://新增数据
                    layer.open({
                        type: 2,
                        title: '角色界面编辑',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['580px', '90%'],
                        content: 'Rleinsert.html?userId='+userId, //iframe的url
                        end:function () {
                            formvalue();//给条件框赋值
                            newTime();//加入时间框
                        }
                    });
                    break;
                case 'select':
                    hidevalue();//给隐藏条件框赋值
                    table2.reload({
                        url:url,
                        where: {
                            attachName: $("#attachName").val(),
                            beginDate:$("#newsTimeS").val(),
                            endDate:$("#newsTimeE").val(),
                            attachPublisher:$("#attachPublisher").val()
                        },
                        page: { curr: 1 }
                    });
                    formvalue();//给条件框赋值
                    newTime();//加入时间框
                    break;
                case 'reload':
                    window.location.reload();
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                if(data.roleValidity==1){
                    var data={roleId:data.roleId,roleValidity:0};
                    layer.confirm('真的删除行么', function(index){
                        var url="../Role/updateRolevalidity.action";
                        $.post(url,data,function(obj){
                            if(obj.state==1){
                                layer.msg("操作成功");
                            }
                            table2.reload();
                        })
                    });
                }
            }else if(obj.event === 'edit'){
                var url="../../AtsAttachmentEmpAction/updateLook";
                var data2={isLook:1,attachId:data.attachId,sort:1};
                $.post(url,data2,function(obj){
                    if(obj.num==1){
                        layer.open({
                            type: 2,
                            title: data.attachName,
                            shadeClose: true,
                            shade: 0.8,
                            area: ['580px', '90%'],
                            content: 'displayshow.html?attachId='+data.attachId+'&attachType='+getQueryString("attachType"), //iframe的url
                            end:function () {
                                formvalue();//给条件框赋值
                                newTime();//加入时间框
                            }
                        });
                    }else if(obj.num==0){
                        layer.alert("亲！此消息内容已被作者删除！");
                    }
                },'json')
            }
        });

    });
</script>
</body>
</html>